<template>
  <div class="bottom-nav fixed bottom-0 left-0 w-full bg-white/95 backdrop-blur-sm border-t border-gray-100">
    <div class="flex justify-around items-center p-2 max-w-lg mx-auto relative">
      <!-- 背景指示器 -->
      <div class="nav-bg-indicator"></div>
      
      <!-- 日记按钮 -->
      <router-link to="/diary" class="nav-item">
        <div class="icon-wrapper">
          <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" 
                  d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"></path>
          </svg>
        </div>
        <span class="nav-text">日记</span>
      </router-link>

      <!-- 智能推荐按钮 -->
      <router-link to="/eat" class="nav-item">
        <div class="icon-wrapper">
          <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                  d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                  d="M8 7.5v3M12 7.5v3M16 7.5v3"/>
          </svg>
        </div>
        <div class="nav-text flex flex-col items-center leading-tight">
          <span>智能</span>
          <span>推荐</span>
        </div>
      </router-link>

      <!-- 我的按钮 -->
      <router-link to="/my" class="nav-item">
        <div class="icon-wrapper">
          <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                  d="M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
          </svg>
        </div>
        <span class="nav-text">我的</span>
      </router-link>
    </div>
  </div>
</template>

<script setup>
import { onMounted } from 'vue';

// 添加触觉反馈
onMounted(() => {
  const navItems = document.querySelectorAll('.nav-item');
  navItems.forEach(item => {
    item.addEventListener('click', () => {
      if ('vibrate' in navigator) {
        navigator.vibrate(10);
      }
    });
  });
});
</script>

<style scoped>
.bottom-nav {
  box-shadow: 0 -1px 6px rgba(0,0,0,0.05);
  z-index: 100;
}

.nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  color: #64748b;
  text-decoration: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 12px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-text {
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
  transition: all 0.3s;
}

/* 活跃状态样式 */
.router-link-active {
  color: #3b82f6;
}

.router-link-active[href*="eat"] {
  color: #22c55e;
}

.router-link-active[href*="my"] {
  color: #8b5cf6;
}

/* 背景指示器 */
.nav-bg-indicator {
  position: absolute;
  bottom: 8px;
  height: 4px;
  width: 24px;
  border-radius: 2px;
  background-color: currentColor;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
}

.router-link-active ~ .nav-bg-indicator {
  opacity: 1;
}

/* 悬浮效果 */
.nav-item:hover {
  color: currentColor;
}

.nav-item:hover .icon-wrapper {
  transform: translateY(-2px);
  background-color: currentColor;
  opacity: 0.1;
}

.nav-item:active .icon-wrapper {
  transform: translateY(0);
}

/* 特定路由的指示器位置 */
.router-link-active[href*="diary"] ~ .nav-bg-indicator {
  transform: translateX(calc(-100% - 32px));
  background-color: #3b82f6;
}

.router-link-active[href*="eat"] ~ .nav-bg-indicator {
  transform: translateX(0);
  background-color: #22c55e;
}

.router-link-active[href*="my"] ~ .nav-bg-indicator {
  transform: translateX(calc(100% + 32px));
  background-color: #8b5cf6;
}

/* 动画效果 */
@keyframes slideUp {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.bottom-nav {
  animation: slideUp 0.3s ease-out;
}

/* 移动端优化 */
@media (max-width: 360px) {
  .nav-item {
    padding: 8px 12px;
  }
  
  .icon-wrapper {
    padding: 6px;
  }
  
  .nav-text {
    font-size: 11px;
  }
}
</style>
